package com.vision.bigDataApi.utils;

import java.io.IOException;

import com.vision.bigDataApi.model.dto.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;


@Component
public class JsonUtilImpl {
	@Autowired
	private ObjectMapper objectMapper;
	/*
	 * 把对象转化为json字符串
	 */
		public String toJson(Object object) {
		try {
			return objectMapper.writeValueAsString(object);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return "";
	}


	public Result toResult(String string) {
		try {
			return objectMapper.readValue(string, Result.class);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

}
